from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService

# 启动浏览器
service = ChromeService(executable_path="D:\Downloads\chromedriver-win64\chromedriver-win64")
driver = webdriver.Chrome(service=service)

# 打开网页
driver.get("https://www.example.com")

# 通过 ID 定位输入框并输入文本
username = driver.find_element(By.ID, "username")
username.send_keys("testuser")

# 通过 Name 定位输入框并输入文本
password = driver.find_element(By.NAME, "password")
password.send_keys("password123")

# 通过 CSS 选择器定位按钮并点击
submit_button = driver.find_element(By.CSS_SELECTOR, "button.submit-btn")
submit_button.click()

# 通过 XPath 定位链接并点击
link = driver.find_element(By.XPATH, "//a[text()='Click Here']")
link.click()

# 关闭浏览器
driver.quit()